<template>
    <cube-scroll class="ratings" :data="computedRatings" :options="scrollOptions">
        <div class="ratings-content">
            <!-- 评价概览 -->
            <div class="overview">
                <!-- 左侧综合评分 -->
                <div class="overview-left">
                    <h1 class="score">{{seller.score}}</h1>
                    <div class="title">综合评分</div>
                    <div class="rank">高于周边 {{seller.rankRate}}%商家</div>
                </div>
                <!-- 右侧分类星级 -->
                <div class="overview-right">
                    <div class="score-wrapper">
                        <span class="title">服务态度</span>
                        <star :size="36" :score="seller.serviceScore"></star>
                        <span class="score">{{seller.serviceScore}}</span>
                    </div>
                    <div class="score-wrapper">
                        <span class="title">商品评价</span>
                        <star :size="36" :score="seller.foodScore"></star>
                        <span class="score">{{seller.foodScore}}</span>
                    </div>
                    <div class="delivery-wrapper">
                        <span class="title">送达时间</span>
                        <span class="delivery">{{seller.deliveryTime}}分钟</span>
                    </div>
                </div>
            </div>
            <split></split>
            <!-- 评论类型 -->
            <rating-select
                :ratings="ratings"
                :onlyContent="onlyContent"
                :selectType="selectType"
                @select="onSelect"
                @toggle="onToggle"
                v-if="ratings.length"
            >
            </rating-select>
            <!-- 评论列表 -->
            <div class="rating-wrapper">
                <ul>
                    <li
                        v-for="(rating,index) in computedRatings"
                        :key="index"
                        class="rating-item border-bottom-1px"
                    >
                        <div class="avatar">
                            <img width="28" height="28" :src="rating.avatar">
                        </div>
                        <div class="content">
                            <h1 class="name">{{rating.username}}</h1>
                            <div class="star-wrapper">
                                <star :size="24" :score="rating.score"></star>
                                <span class="delivery" v-show="rating.deliveryTime">
                                    {{rating.deliveryTime}}分种
                                </span>
                            </div>
                            <p class="text">{{rating.text}}</p>
                            <div class="recommend" v-show="rating.recommend && rating.recommend.length">
                                <span class="icon-thumb_up"></span>
                                <span
                                    class="item"
                                    v-for="(item,index) in rating.recommend"
                                    :key="index"
                                >
                                    {{item}}
                                </span>
                            </div>
                            <div class="time">
                                {{format(rating.rateTime)}}
                            </div>
                        </div>
                    </li>
                </ul>
            </div>
        </div>
    </cube-scroll>
</template>

<script>
    import Star from 'components/star/star'
    import Split from 'components/split/split'
    import RatingSelect from 'components/rating-select/rating-select'
    import ratingMixin from 'common/mixins/rating'
    // 滑动参数，防止页面斜线滑动
    import { optionMixin } from 'common/mixins/scroll'

    import { getRatings } from 'api'

    export default {
        mixins: [ratingMixin, optionMixin],
        name: 'ratings',
        props: {
          data: {
              type: Object
          }
        },
        data() {
            return {
                ratings: []
            }
        },
        computed: {
            seller() {
                return this.data.seller || {}
            }
        },
        methods: {
            fetch() {
                if (!this.fetched) {
                    this.fetched = true
                    getRatings({
                        id: this.seller.id
                    }).then((ratings) => {
                        this.ratings = ratings
                    })
                }
            }
        },
        components: {
            Star,
            Split,
            RatingSelect
        }
    }
</script>

<style lang="stylus" scoped>
    @import "~common/stylus/variable"
    @import "~common/stylus/mixin"

    .ratings
        position: relative
        text-align: left
        white-space: normal
        height: 100%
        // 评分概述
        .overview
            display: flex
            padding: 18px 0
            // 总评分
            .overview-left
                flex: 0 0 137px
                padding: 6px 0
                // 兼容不支持flex的浏览器
                width: 137px
                border-right: 1px solid $color-col-line
                text-align: center
                // 对小屏幕进行适配
                @media only screen and (max-width: 320px)
                    flex: 0 0 120px
                    width: 120px
                .score
                    margin-bottom: 6px
                    line-height: 28px
                    font-size: $fontsize-large-xxx
                    color: $color-orange
                .title
                    margin-bottom: 8px
                    line-height: 12px
                    font-size: $fontsize-small
                    color: $color-dark-grey
                .rank
                    line-height: 10px
                    font-size: $fontsize-small-s
                    color: $color-light-grey
            // 右侧分项得分
            .overview-right
                flex: 1
                padding: 6px 0 6px 24px
                // 对小屏幕进行适配
                @media only screen and (max-width: 320px)
                    padding-left: 6px
                // 得分
                .score-wrapper
                    display: flex
                    align-items: center
                    margin-bottom: 8px
                    .title, .score
                        line-height: 18px
                        font-size: $fontsize-small
                    .title
                        color: $color-dark-grey
                    .score
                        color: $color-orange
                    .star
                        margin: 0 12px

                // 送达时间
                .delivery-wrapper
                    display: flex
                    align-items: center
                    .title, .delivery
                        font-size: $fontsize-small
                    .title
                        line-height: 18px
                        color: $color-dark-grey
                    .delivery
                        margin-left: 12px
                        color: $color-light-grey
        // 评价列表
        .rating-wrapper
            padding: 0 18px
            .rating-item
                display: flex
                padding: 18px 0
                &:last-child
                    border-none()
                .avatar
                    flex: 0 0 28px
                    width: 28px
                    margin-right: 12px
                    img
                        height: auto
                        border-radius: 50%
                .content
                    position: relative
                    flex: 1
                    .name
                        margin-bottom: 4px
                        line-height: 12px
                        font-size: $fontsize-small-s
                        color: $color-dark-grey
                    .star-wrapper
                        margin-bottom: 6px
                        display: flex
                        align-items: center
                        .star
                            margin-right: 6px
                        .delivery
                            font-size: $fontsize-small-s
                            color: $color-light-grey
                    .text
                        margin-bottom: 8px
                        line-height: 18px
                        color: $color-dark-grey
                        font-size: $fontsize-small
                    .recommend
                        display: flex
                        align-items: center
                        flex-wrap: wrap
                        line-height: 16px
                        .icon-thumb_up, .item
                            margin: 0 8px 4px 0
                            font-size: $fontsize-small-s
                        .icon-thumb_up
                            color: $color-blue
                        .item
                            padding: 0 6px
                            border: 1px solid $color-row-line
                            border-radius: 1px
                            color: $color-light-grey
                            background: $color-white
                    .time
                        position: absolute
                        top: 0
                        right: 0
                        line-height: 12px
                        font-size: $fontsize-small
                        color: $color-light-grey

</style>
